package com.lifa.controller;

import com.lifa.dao.ChanpindanweiDao;
import com.lifa.entity.Chanpindanwei;
import com.lifa.service.ChanpindanweiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/chanpindanwei")
@Scope("prototype")
public class ChanpindanweiController {
    @Autowired
    private ChanpindanweiDao chanpindanweiDao;
    @Autowired
    private ChanpindanweiService chanpindanweiService;

    /**
     * 查询全部
     * @return
     */
    @RequestMapping("/chanpindanwei1")
    @ResponseBody
    public List<Chanpindanwei> list(){
        return chanpindanweiDao.query();
    }

    /**
     * 根据商品单位id删除信息
     * @param chanpindanwei_Id
     * @return
     */
    @RequestMapping("/shanchu")
    @ResponseBody
   public int shanchu(int chanpindanwei_Id){
        return chanpindanweiService.delete(chanpindanwei_Id);
    }

    /**
     * 添加商品单位信息
     * @param chanpindanwei
     * @return
     */
    @RequestMapping("/tiajia")
    @ResponseBody
    public int tiajia(Chanpindanwei chanpindanwei){
        return chanpindanweiDao.insert(chanpindanwei);
    }

    /**
     * 获取到商品单位id
     * @param chanpindanwei_Id
     * @return
     */
    @RequestMapping("/queryId")
    @ResponseBody
    public Chanpindanwei queryId(int chanpindanwei_Id){
        return chanpindanweiService.queryId(chanpindanwei_Id);
    }

    /**
     * 根据商品单位id修改信息
     * @param chanpindanwei
     * @return
     */
    @RequestMapping("/xiugai")
    @ResponseBody
    public int xiugai(Chanpindanwei chanpindanwei){
        return chanpindanweiService.update(chanpindanwei);
    }
}
